const express = require('express')
const router = express.Router()
const articleModel = require('../model/articlesModel')

router.get('/api/articles', async (req, res) => {
  const reqArticle = req.query
  let body = {}
  if (reqArticle.articleName) {
    const article = await articleModel.create({
      articleName: reqArticle.articleName,
      articleContent: reqArticle.articleContent
    })
    if (article) {
      body = {
        code: 1,
        msg: 'create success',
        data: reqArticle
      }
    } else {
      body = {
        code: 0,
        msg: 'create failed'
      }
    }
  }
  res.send(body)
})
module.exports = router
